<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Dashboard V.1 | Kiaalap - Kiaalap Admin Template</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- favicon
		============================================ -->
    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">
    <!-- Google Fonts
		============================================ -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700,900" rel="stylesheet">
    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- Lobibox CSS
        ============================================ -->
    <link rel="stylesheet" href="css/notifications/Lobibox.min.css">

    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/font-awesome.min.css">


    <!-- DatetimePicker CSS
        ============================================ -->
    <link rel="stylesheet" href="css/datetimepicker/bootstrap-datetimepicker.min.css">

    <!-- owl.carousel CSS
		============================================ -->
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" href="css/owl.theme.css">
    <link rel="stylesheet" href="css/owl.transitions.css">
    <!-- animate CSS
		============================================ -->
    <link rel="stylesheet" href="css/animate.css">
    <!-- normalize CSS
		============================================ -->
    <link rel="stylesheet" href="css/normalize.css">
    <!-- meanmenu icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/meanmenu.min.css">
    <!-- main CSS
		============================================ -->
    <link rel="stylesheet" href="css/main.css">
    <!-- educate icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/educate-custon-icon.css">
    <!-- morrisjs CSS
		============================================ -->
    <link rel="stylesheet" href="css/morrisjs/morris.css">
    <!-- mCustomScrollbar CSS
		============================================ -->
    <link rel="stylesheet" href="css/scrollbar/jquery.mCustomScrollbar.min.css">
    <!-- metisMenu CSS
		============================================ -->
    <link rel="stylesheet" href="css/metisMenu/metisMenu.min.css">
    <link rel="stylesheet" href="css/metisMenu/metisMenu-vertical.css">
    <!-- calendar CSS
		============================================ -->
    <link rel="stylesheet" href="css/calendar/fullcalendar.min.css">
    <link rel="stylesheet" href="css/calendar/fullcalendar.print.min.css">

    <!-- form CSS
		============================================ -->
    <link rel="stylesheet" href="css/form/all-type-forms.css">

    <!-- style CSS
		============================================ -->
    <link rel="stylesheet" href="css/style.css">
    <!-- responsive CSS
		============================================ -->
    <link rel="stylesheet" href="css/responsive.css">
    <link rel="stylesheet" href="css/mloading.css">
    <!-- modernizr JS
		============================================ -->
    <script src="js/jquery.min.js"></script>

    <script src="js/vendor/modernizr-2.8.3.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/jquery.cookie.min.js"></script>

    <style>
        .fileBox {
            position: relative;
            background-color: #ff0000;

            border-radius: 10px;
            /**
             *  relative 相对定位两个作用：1.微调元素；2.子绝父相。
             */
        }

        .importedExcelFile {
            height: 10px;
            width: 120px;
            opacity: 0;

        }

        .coverFileBtn {
            display: block;
            position: absolute;
            left: 0;
            top: 0;
            background-color: red;
            height: 34px;
            width: 120px;
            border: none;
            z-index: -1;
            color: #fff;

        }
        .pf {
            display: block;
            position: relative;
            left: 0;
            top: 0;
            background-color: red;
            height: 20px;
            width: 120px;
            border: none;
            z-index: 1;
            color: #fff;
            border-radius: 10px;

        }
        .pf2{
            text-align: center;

        }
    </style>


</head>

<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade
    your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Start Left menu area -->
<div class="left-sidebar-pro">
    <nav id="sidebar" class="">
        <div class="sidebar-header">
            <a href="index.html"><img class="main-logo" src="img/logo/logo.png" alt=""/></a>
            <strong><a href="index.html"><img src="img/logo/logosn.png" alt=""/></a></strong>
        </div>
        <div class="left-custom-menu-adp-wrap comment-scrollbar">
            <nav class="sidebar-nav left-sidebar-menu-pro">
                <ul class="metismenu" id="menu1">
                    <li class="active">
                        <a class="has-arrow" href="index.html">
                            <span class="fa fa-id-card"></span>
                            <span class="mini-click-non">用户信息</span>
                        </a>
                        <ul class="submenu-angle" aria-expanded="true">
                            <li><a href="dataStatistics.html"><span class="mini-sub-pro">图表信息统计</span></a></li>
                            <li><a href="index.html"><span class="mini-sub-pro">用户列表</span></a></li>
                            <li><a href="goodsManager.html"><span class="mini-sub-pro">商品列表</span></a></li>
                            <li><a href="order.html"><span class="mini-sub-pro">订单管理</span></a></li>
                            <li><a href="payPage.html"><span class="mini-sub-pro">支付流水列表</span></a></li>
                            <li><a href="logManagement.html"><span class="mini-sub-pro">日志管理</span></a></li>
                            <li><a href="dataPush.html"><span class="mini-sub-pro">级光推送</span></a></li>

                        </ul>
                    </li>
                    <li>
                        <a title="Landing Page" href="sysUser.html" aria-expanded="false"><span
                                class="fa fa-user-circle-o" aria-hidden="true"></span> <span
                                class="mini-click-non">系统用户</span></a>
                    </li>

                </ul>
            </nav>
        </div>
    </nav>
</div>
<!-- End Left menu area -->
<!-- Start Welcome area -->
<div class="all-content-wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="logo-pro">
                    <a href="index.html"><img class="main-logo" src="img/logo/logo.png" alt=""/></a>
                </div>
            </div>
        </div>
    </div>
    <div class="header-advance-area">
        <div class="header-top-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="header-top-wraper">
                            <div class="row">
                                <div class="col-lg-1 col-md-0 col-sm-1 col-xs-12">
                                    <div class="menu-switcher-pro">
                                        <button type="button" id="sidebarCollapse"
                                                class="btn bar-button-pro header-drl-controller-btn btn-info navbar-btn">
                                            <i class="fa fa-bars"></i>
                                        </button>
                                    </div>
                                </div>
                                <div class="col-lg-6 col-md-7 col-sm-6 col-xs-12">
                                    <div class="header-top-menu tabl-d-n">
                                        <ul class="nav navbar-nav mai-top-nav">
                                            <li class="nav-item"><a href="#" class="nav-link"></a>
                                            </li>
                                            <li class="nav-item"><a href="#" class="nav-link"></a>
                                            </li>
                                            <li class="nav-item"><a href="#" class="nav-link"></a>
                                            </li>
                                            <li class="nav-item dropdown res-dis-nn">

                                                <div role="menu" class="dropdown-menu animated zoomIn">
                                                    <a href="#" class="dropdown-item">Documentation</a>
                                                    <a href="#" class="dropdown-item">Expert Backend</a>
                                                    <a href="#" class="dropdown-item">Expert FrontEnd</a>
                                                    <a href="#" class="dropdown-item">Contact Support</a>
                                                </div>
                                            </li>
                                            <li class="nav-item"><a href="#" class="nav-link"></a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
                                    <div class="header-right-info">
                                        <ul class="nav navbar-nav mai-top-nav header-right-menu">
                                            <li class="nav-item">
                                                <a href="#" data-toggle="dropdown" role="button" aria-expanded="false"
                                                   class="nav-link dropdown-toggle">
                                                    <span class="admin-name" id="admin-name">用户管理</span>
                                                    <span class="admin-name2" id="admin-nam2"></span>
                                                </a>
                                                <ul role="menu"
                                                    class="dropdown-header-top author-log dropdown-menu animated zoomIn">
                                                    <li><a href="sysUser.html"><span
                                                            class="edu-icon edu-home-admin author-log-ic"></span><button>管理员信息</button></a>
                                                    <li><a><span
                                                            class="edu-icon edu-settings author-log-ic"></span><button  onclick="loginOut()">切换登录</button></a>
                                                    <li><a><span
                                                            class="edu-icon edu-settings author-log-ic" ></span><button onclick="loginOut()">退出登录</button>
                                                    </a></li>

                                                </ul>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="container-fluid" style="padding: 20px 15px 0 15px;">


            <!-- 首页页面 -->


            <div style="background-color: #ffffff; border-radius: 3px; padding: 12px;">
                <form class="form-inline" id="searchForm" onsubmit="javascript: return false;">
                    <div class="form-group">
                        <label for="name">用户名: </label>
                        <input autocomplete="off" class="form-control" name="name" id="name">
                    </div>
                    <div class="form-group">
                        <label for="sex">性别: </label>
                        <select class="form-control" name="sex" id="sex">
                            <option value="-1">全部</option>
                            <option value="F">女</option>
                            <option value="M">男</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="status">状态: </label>
                        <select class="form-control" name="status" id="status">
                            <option value="-1">全部</option>
                            <option value="1">激活</option>
                            <option value="0">未激活</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="email">邮件: </label>
                        <input autocomplete="off" class="form-control" name="email" id="email">
                    </div>
                    <div class="form-group">
                        <label>注册日期: </label>
                        <input class="form-control" readonly autocomplete="off" name="begin" id="beginRegisterDate"> -
                        <input autocomplete="off" readonly class="form-control" name="end" id="endRegisterDate">
                    </div>
                    <div class="form-group">
                        <button class="btn btn-danger" onclick="querySearch()">搜索</button>
                        <button autocomplete="off" class="btn btn-danger" onclick="resetSearch()">重置</button>
                    </div>
                </form>
                <div class="fileBox" style="display: inline-block">
                    <input onchange="chooseExcel(this)" id="fileBtn" type="file" class="importedExcelFile">
                    <div class="pf"><p class="pf2">选择excel文件</p></div>
                    <button class="coverFileBtn">选择excel文件</button>
                </div>
                <input id="importFileName" class="form-control">
                <button onclick="sureImportExcel()" class="btn btn-warning">确认导入</button>
                <button onclick="excelExport()" class="btn btn-success">导出</button>
            <button onclick="downTemplate()">模板下载</button>

                <table id="dataTable" class="table table-hover table-bordered" style="margin-top: 13px;"></table>
            </div>
            <!--
            额外加一列，写个按钮查看用户的地址信息。
            -->

            <div class="modal" id="showAddressModal" data-backdrop="static">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button class="close" onclick="destoryAdressTableAndHideModal()">
                                <span>&times;</span>
                            </button>
                            <h3 class="modal-title">收货地址</h3>
                        </div>
                        <div class="modal-body">
                            <table id="addressDataTable" class="table table-striped"></table>
                        </div>
                    </div>
                </div>
            </div>


            <div class="modal" id="showCartModal" data-backdrop="static">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button class="close" onclick="destoryCartTableAndHideModal()">
                                <span>&times;</span>
                            </button>
                            <h3 class="modal-title">购物车</h3>
                        </div>
                        <div class="modal-body">
                            <table id="cartDataTable" class="table table-striped"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <!-- 尾部页面 -->


    </div>
</div>
</div>

<!-- jquery
============================================ -->
<script src="js/vendor/jquery-1.12.4.min.js"></script>
<!-- bootstrap JS
============================================ -->
<script src="js/bootstrap.min.js"></script>
<!-- wow JS  动画效果js
============================================ -->
<script src="js/wow.min.js"></script>
<!-- price-slider JS
============================================ -->
<script src="js/jquery-price-slider.js"></script>
<!-- meanmenu JS
============================================ -->
<script src="js/jquery.meanmenu.js"></script>
<!-- owl.carousel JS
============================================ -->
<script src="js/owl.carousel.min.js"></script>
<!-- sticky JS
============================================ -->
<script src="js/jquery.sticky.js"></script>
<!-- scrollUp JS
============================================ -->
<script src="js/jquery.scrollUp.min.js"></script>
<!-- counterup JS
============================================ -->
<script src="js/counterup/jquery.counterup.min.js"></script>
<script src="js/counterup/waypoints.min.js"></script>
<script src="js/counterup/counterup-active.js"></script>
<!-- mCustomScrollbar JS
============================================ -->
<script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="js/scrollbar/mCustomScrollbar-active.js"></script>
<!-- metisMenu JS
============================================ -->
<script src="js/metisMenu/metisMenu.min.js"></script>
<script src="js/metisMenu/metisMenu-active.js"></script>


<script src="js/sparkline/jquery.sparkline.min.js"></script>
<script src="js/sparkline/jquery.charts-sparkline.js"></script>
<script src="js/sparkline/sparkline-active.js"></script>
<!-- calendar JS
============================================ -->
<script src="js/calendar/moment.min.js"></script>

<script src="js/calendar/fullcalendar.min.js"></script>
<script src="js/calendar/fullcalendar-active.js"></script>
<!-- plugins JS
============================================ -->
<script src="js/plugins.js"></script>
<!-- main JS
============================================ -->
<script src="js/main.js"></script>

<!-- tawk chat JS  聊天系统js
<script src="js/tawk-chat.js"></script>
============================================ -->

<script src="js/data-table/bootstrap-table.js"></script>
<script src="js/data-table/bootstrap-table-zh-CN.js"></script>

<script src="js/notifications/Lobibox.js"></script>
<script src="js/datepicker/bootstrap-datetimepicker.min.js"></script>
<script src="js/datepicker/bootstrap-datetimepicker.zh-CN.js"></script>

<script src="js/mloading.js"></script>
<script src="js/jquery.cookie.min.js"></script>
<script src="js/mloading.js"></script>
<script src="js/login-status.js"></script>
</body>
<script>
    if($.cookie('frontedUsername')){

    function loginOut(){

        $.ajax({
            url:'http://localhost:8080/sysUser/loginOut',
            method:'get',
            success:function (_data) {
               alert(_data.msg);
              $.cookie('frontedUsername','',path='/');
               window.location="/shop/login.html";
            }

        })
    }
    $('#beginRegisterDate, #endRegisterDate').datetimepicker({
        // 格式化 yyyy-mm-dd hh:ii:ss 年-月-日 时-分-秒
        format: 'yyyy-mm-dd hh:ii:ss'
    })

    $('#dataTable').bootstrapTable({
        url: 'http://localhost:8080/user/getUser',
        method: 'get', //请求的方式
        // columns: 是定义列的信息， title表头信息, field表示从返回的json数据中取对应的属性的
        columns: [{
            field: 'id',
            title: 'ID',
            align: 'center'
        }, {
            field: 'name',
            title: '姓名',
            align: 'center'
        },
            // formatter要接收一个函数, 是对数据进行处理，该函数接收四个参数。
            {
                field: 'sex',
                title: '性别',
                align: 'center',
                formatter: formatSex
            }, {
                field: 'status',
                title: '状态',
                align: 'center',
                formatter: formatStatus
            }, {
                field: 'phone',
                title: '电话',
                align: 'center'
            }, {
                field: 'email',
                title: '邮件',
                align: 'center'
            }, {
                field: 'registerDate',
                title: '注册日期',
                align: 'center',
                formatter: formatRegisterDate
            }, {
                title: '操作',
                formatter: addProcessBtns
            }
        ],
        // 查询的参数，是根据该方法的返回值来定的, params中默认的数据格式：
        //      {limit: 10, offset: 0, order: "asc", search: undefined, sort: undefined}
        // limit是每页默认的每页显示的数据, offset(中文翻译是偏移量), 映射分页中指的是 beginIndex   select * from user limit offset, 10;
        // order 是查询的顺序; 如果是get请求会默认将该函数的返回值拼接到请求的url后面:
        //                     http://localhost:8081/my_cart_war_exploded/user?offset=0&limit=10&order=asc&method=getUserPageData
        queryParams: function (params) {

            var name = $('#name').val(); //获取查询表单name的值
            var sex = $('#sex').val();
            var status = $('#status').val();
            var email = $('#email').val();
            var begin = $('#beginRegisterDate').val(); //重置name
            var end = $('#endRegisterDate').val(); //重置name

            params.name = name;
            params.sex = sex;
            params.status = status;
            params.email = email;
            params.begin = begin;
            params.end = end;
            return params;
            // 最终的请求会默认帮我们带上这些参数
            //http://localhost:8081/my_cart_war_exploded/user?order=asc&offset=0&limit=10&name=&gender=-1&status=-1&email=&begin=&end=&method=getUserPageData
        },
        pageList: [10, 15, 20], // 切换每页显示多少条数据
        pagination: true, //表示意思是要分页, 默认是false
        // 在那边分页，值为 "client", "server", client的意思一次性将数据全部拿到，然后客户端分页。
        // server, 在服务器端分页, 每次查分页的数据的时候到服务器去请求。
        sidePagination: 'server'
    })

    /**
     * 最终表格中显示的数据以该函数的返回值为准
     * value是当前格子的值。
     * row是当前行的数据。
     * index是当前数据的索引。
     */
    function formatSex(value, row, index) {
        return 'F' == value ? '女' : '男';
    }

    // 格式化状态
    function formatStatus(value) {
        // 1表示激活状态(要看数据库)
        if (value == 1) {
            return '<span class="label label-success">激活</span>'
        } else {
            return '<span class="label label-danger">未激活</span>'
        }
    }

    //格式化注册日期
    function formatRegisterDate(value) {
        // 使用moment这个库来完成日期的格式化
        return moment(value).format('YYYY-MM-DD HH:mm:ss');
    }

    /**
     * 该方法会返回操作按钮：
     *      1. 查看用户所有的收货地址(必须的)。
     *      2. 对于未激活的用户, 得有激活按钮, 激活的用户不用加,激活的用户可以禁止。
     *

     */
    function addProcessBtns(value, row) {
        var btns = '<button class="btn btn-info btn-xs" onclick="showTakeDeliveryAddress(' + row.id + ')">查看收货地址</button>' +
            '  <button onclick="showShoppingCartData(' + row.id + ')" class="btn btn-primary btn-xs">查看购物车</button>';

        //如果用户是未激活状态, 添加激活按钮
        if (row.status != 1) {
            btns += '  <button class="btn btn-success btn-xs" onclick="activeUser(' + row.id + ')">激活</button>'
        }
        if (row.status == 1) {
            btns += '<button class="btn btn-danger btn-xs" onclick="banUser(' + row.id + ')">禁用</button>'
        }
        return btns;
    }

    // 查看收货地址
    function showTakeDeliveryAddress(userId) {
        console.log(userId)
        $('#showAddressModal').modal('show');
        $('#addressDataTable').bootstrapTable({

            url: 'http://localhost:8080/order/show/' + userId,
            method: "get",
            columns: [{
                field: 'name',
                align: 'center',
                title: '收件人姓名'
            }, {
                field: 'phone',
                align: 'center',
                title: '收件人电话'
            }, {
                field: 'detail',
                align: 'center',
                title: '收货地址'
            }, {
                field: 'state',
                align: 'center',
                title: '默认地址',
                formatter: function (value) {
                    if (value == 1) { //当value的值为1的时候，表示默认收货地址
                        return '<span class="label label-success">默认</span>';
                    }
                    return "否";
                }
            }],
            // var obj = {age: 10};  obj.name = 'zhangsan';
            queryParams: function (params) {
                params.userId = userId;
                return params;
            }
        })
    }

    // 查看购物车
    function showShoppingCartData(userId) {
        $('#showCartModal').modal('show');
        $('#cartDataTable').bootstrapTable({
            url: "http://localhost:8080/Goods/cart/" + userId,
            method: "GET",
            columns: [{
                field: "goodId",
                align: "center",
                title: "商品id"
            }, {
                field: "title",
                align: "center",
                title: "商品名字"
            }, {
                field: "num",
                align: "center",
                title: "数量"
            },],
            queryParams: function (params) {
                params.userId = userId;
                return params;
            }
        })
    }

    // 销毁表格, 然后影藏模态窗
    function destoryAdressTableAndHideModal() {
        $('#showAddressModal').modal('hide');
        // 因为模态窗中的表格, 没有分页，所以将数据直接缓存在客户端，当重新请求的时候并不会发送网络请求，
        // 导致看不同用户的收货地址的时候, 看到的数据是上一次的，所以每次影藏要将表格销毁掉。
        // https://www.bootstrap-table.com.cn/doc/api/methods/#destroy
        $('#addressDataTable').bootstrapTable('destroy'); // destroy是固定值
    }

        $('#admin-name').hide();
        $('#admin-nam2').html('欢迎你'+$.cookie('frontedUsername'));
    }

    //销毁表格, 然后影藏模态窗
    function destoryCartTableAndHideModal() {

        $('#showCartModal').modal('hide');
        // 因为模态窗中的表格, 没有分页，所以将数据直接缓存在客户端，当重新请求的时候并不会发送网络请求，
        // 导致看不同用户的收货地址的时候, 看到的数据是上一次的，所以每次影藏要将表格销毁掉。
        // https://www.bootstrap-table.com.cn/doc/api/methods/#destroy
        $('#cartDataTable').bootstrapTable('destroy'); // destroy是固定值
    }

    // 激活用户
    function activeUser(id) {
        $.ajax({
            url: 'http://localhost:8080/user/active/' + id,
            dataType: 'json',
            type: 'put',
            success: function (_data) {
                if (_data.code > 0) {
                    // if(confirm("是否激活"+id+"用户"))

                    $('#dataTable').bootstrapTable('refresh');
                    // } else { //激活失败, 提示用户.
                    //     Lobibox.notify('info', {
                    //         title: '提示',
                    //         msg: '请联系管理员',
                    //         size: 'mini'
                    //     })

                }
            },
            error: function (_data) {
                alert(_data.msg)
                // console.log(_data)
                // Lobibox.notify('info', {
                //     title: '提示',
                //     msg: '激活失败, 请联系管理员',
                //     size: 'mini'
                // })
            }
        })
    }

    //禁用活跃用户
    function banUser(userId) {
        $.ajax({
            // url: 'http://localhost:8080/java_project3_war_exploded/user',
            url: 'http://localhost:8080/user/ban/' + userId,
            dataType: 'json',
            type: 'put',
            success: function (_data) {
                //禁用成功后要加载表格的数据
                if (_data.code > 0) {
                    $('#dataTable').bootstrapTable('refresh');
                } else {
                    alert(_data.msg)
                    // Lobibox.notify('info', {
                    //     title: '提示',
                    //     msg: '禁用失败，请联系管理员',
                    //     size: 'mini'
                    // })
                }
            }
        })
    }

    // 搜索
    function querySearch() {
        // 解决翻页之后, 还是停留在以前的页面问题, 使用selectPage, 意思是回到第一页
        $('#dataTable').bootstrapTable('selectPage', 1);
    }

    /**
     * 重置搜索条件:
     *    1.将所有的搜索条件归位；
     *    2.刷新表格数据。
     */
    function resetSearch() {
        $('#name').val(''); //重置name
        $('#sex').val('-1'); //重置性别
        $('#status').val('-1'); //重置状态
        $('#email').val('');
        $('#beginRegisterDate').val('');
        $('#endRegisterDate').val('');
        querySearch();
    }

    // // 显示错误提示信息
    // function showErrorBox(msgText) {
    //     Lobibox.notify('warning', {
    //         size: 'mini',
    //         delay: 2000,
    //         delayIndicator: false,
    //         title: false, //不给title
    //         msg: msgText,
    //          sound: false // 不要音频
    //     })
    // }
    if ($.cookie('frontedUsername')) {
        $('#admin-name').html('欢迎您,' + $.cookie('frontedUsername'));
    }

    /**
     * 1. 获取浏览器地址栏，然后截取路径。
     * 2. 根据路径使用jquery的选择器让其背景颜色变一下。
     */
    var url = window.location.href;   //获取浏览器地址栏 http://localhost:8081/my_cart_war_exploded/admin/index.html

    var index = url.lastIndexOf("/");  //获取最后一个 / 所在的索引的位置

    var path = '/admin' + url.substring(index);  // /admin/index.html

    $('a[href$="' + path + '"]').css('background-color', '#f7f8fb');


    // 点击 "文件按钮", 展示文件名
    function chooseExcel(fileTag) {
        // files 拿到的是所有的文件， 可以丢多个文件，所以是个数组。
        var currentFile = fileTag.files[0]; //取第一个文件

        var fileName = currentFile.name; //获取文件名


        $('#importFileName').val(fileName);
    }

    // 点击 “确认导入” 按钮
    function sureImportExcel() {

        var fileBtn = document.getElementById('fileBtn');
        var file = fileBtn.files[0]; //获取要上传的文件

        $('body').mLoading('show');

        // $('body').mLoading({
        //     text: "正在导入中...", //加载文字，默认值：加载中...
        //     mask: true //是否显示遮罩效果，默认显示
        // });

        // FormData是 H5新增的对象，主要用于异步文件上传
        var formData = new FormData();
        formData.append("userExcel", file); //

        $.ajax({
            url: 'http://localhost:8080/user/import',
            type: 'post',
            dataType: 'json',
            // 因为默认的 contentType是 application/x-www-form-urlencoded, 设置false目的是将 FormData 直接丢上去。
            contentType: false,
            data: formData,
            // 数据不作任何的处理
            processData: false,
            success: function (_data) {
                fileBtn.value = '';
                $('#importFileName').val('')
                $('body').mLoading('hide'); //隐藏加载框
                if (_data.code > 0) {
                    alert('导入成功');
                    $('#dataTable').bootstrapTable('selectPage', 1);
                } else {
                    alert('导入失败')
                }
            }
        })
    }

    // 导出Excel, 说白就是下载
    function excelExport() {

        // 前提是 form必须有名字
        // name=fef&gender=M&begin=2020-10-13&end=2020-10-21&companyId=1
        var searchContent = $('#searchForm').serialize();
        location.href = 'http://localhost:8080/user/export?' + searchContent
    }

    // 导出模板, 说白就是下载
    function downTemplate() {

        // 前提是 form必须有名字
        // name=fef&gender=M&begin=2020-10-13&end=2020-10-21&companyId=1
        location.href = 'http://localhost:8080/user/down?' ;
    }
</script>
</html>

